package org.nowcoder.leetcode.twoPointers;


/**
 * Title  : 27. Remove Element
 * Source : https://leetcode.cn/problems/remove-element/?envType=study-plan-v2&envId=top-interview-150
 * Author : XrazYang
 * Date   : 2023-07-05
 */
public class LeetCode_27 {
    public int removeElement(int[] nums, int val) {
        int k = nums.length - 1;
        for (int i = 0; i <= k; ) {
            if (nums[i] == val) {
                nums[i] = nums[k--];
            } else {
                i++;
            }
        }
        return k + 1;
    }
}
